# coding: utf-8
from constants import apb
from typing import Any, List, Dict
from utils.logger_handle import logger
from utils.requests_handle import Response


class DouPageIndex:
    """首页"""
    
    def index_userinfo(self) -> Any | Response:
        """首页-用户信息"""
        payLoad: dict = {}
        userinfoResponse: Any | Response = apb.required_json(
            method="post",
            url="https://www.dougongdesign.com/api/sso/user/info",
            json=payLoad
        )
        apb.assertEqualValue(200, userinfoResponse.status_code)
        return userinfoResponse
    
    def index_message(self, is_read: int = 0, **kwargs) -> Any | Response:
        """
        首页-???
        @params: (int)is_read: ???, default 0
        @params: (int)pageIndex: 分页, default 1
        @params: (int)pageSize: 页数, default 20
        @params: (str)toUser: 用户id, default 1674294787392000001
        """
        payLoad: dict = {
            "isRead": is_read,
            "pageIndex": kwargs.get("pageIndex", 1),
            "pageSize": kwargs.get("pageSize", 20),
            "toUser": kwargs.get("toUser", "1674294787392000001")
        }
        msgResponse: Any | Response = apb.required_json(
            method="post",
            url="https://www.dougongdesign.com/api/message/msg/page/list",
            json=payLoad
        )
        return msgResponse
    
    def index_detail(self, index_type: str = "housetype", number: int = 20) -> Any | Response:
        """
        首页-户型库、构件库、材质库、图例库
        @params: (str)index_type: 首页类型 default housetype
        @params: (int)number: 分页, default 20
        """
        payLoad: dict = {
            "limit": number
        }
        match index_type:
            case "housetype":
                point: str = f"/housetype/home/hot/{number}"
            case "component":
                point: str = "/component/component/hot"
            case "render":
                point: str = "/render/render/hot"
            case "legend":
                point: str = "/legend/legend/hot"
            case _:
                point: str = ""
        indexDetailResponse: Any | Response = apb.dou_request(
            method="post",
            point=point,
            json=payLoad
        )
        return indexDetailResponse
